/**
 * Created by IntelliJ IDEA.
 * User: maticm
 * Date: Oct 8, 2003
 * Time: 5:16:50 PM
 * To change this template use Options | File Templates.
 */

package com.generalynx.common.web.navigation;

import com.generalynx.common.web.module.Module;
import com.generalynx.common.resources.Resources;
import com.generalynx.common.constants.WebConst;

public class BasicMenuItemRenderer implements IMenuItemRenderer {

    public String permittedItem(Module node) {
        return getMainFrameLink(node, false);
    }

    protected String getMainFrameLink(Module node, boolean on) {
        return getLink(node, on, null);
    }

    protected String getLink(Module node, boolean on, String target) {
        StringBuffer a = new StringBuffer("<a href=\"");
        a.append(getIndexHref(node));
        a.append("\"");
        if (target != null) {
            a.append(" target=\"");
            a.append(target);
            a.append("\"");
        }
        a.append(">");
        a.append(getItemHtml(node, on));
        a.append("</a>");
        return a.toString();
    }

    protected String getIndexHref(Module node) {
        String action = (node.getAction() != null) ? node.getAction() : "main";
        String query = (node.getQuery() != null) ? "&" + node.getQuery() : "";
        return WebConst.FRONTCONTROLLER + "/" + action + ".htm?module=" + node.getId() + query;
    }

    protected String getLanguageId() {
        return Resources.getString(Resources.LANG);
    }

    public String restrictedItem(Module node) {
        return getItemHtml(node, false);
    }

    public String chosenItem(Module node) {
        return getMainFrameLink(node, true);
    }

    protected String getItemHtml(Module node, boolean on) {
        return node.getLabel();
    }

}
